package com.taotao.manage.controller.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.manage.pojo.Item;
import com.taotao.manage.pojo.ItemDesc;
import com.taotao.manage.service.ItemDescService;
import com.taotao.manage.service.ItemService;

/**
 * 对外提供的api接口
 * 商品和商品描述
 * 
 * @author Beck
 *
 */
@Controller
@RequestMapping("api/item")
public class APIItemController {
	@Autowired
	private ItemService itemService;

	@Autowired
	private ItemDescService itemDescService;
	
	/**
	 * 异步
	 * 根据商品的id，获取商品对象的接口
	 * 参数: 商品的id
	 * 返回值: 商品对象
	 */
	@RequestMapping(value="{itemId}")
	public ResponseEntity<Item> getItemById(@PathVariable("itemId") Long id){
		try {
			Item item = itemService.queryById(id);
			return ResponseEntity.status(HttpStatus.OK).body(item);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
	
	/**
	 * 异步
	 * 根据商品的id，获取商品描述对象的接口
	 * 参数: 商品的id
	 * 返回值: 商品描述对象
	 */
	@RequestMapping(value="desc/{itemId}")
	public ResponseEntity<ItemDesc> getItemDescById(@PathVariable("itemId") Long id){
		try {
			ItemDesc itemDesc = itemDescService.queryById(id);
			return ResponseEntity.status(HttpStatus.OK).body(itemDesc);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
	
	
}
